﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using DWF.Studio.Share.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.ScriptEngine.IPC.Msg
{
    public class Message
    {
        /// <summary>
        /// 引擎id
        /// </summary>
        public string EngineId
        {
            set;
            get;
        }

        /// <summary>
        /// 引擎类型
        /// </summary>
        public EEngineType EngineType
        {
            set;
            get;
        }

        /// <summary>
        /// 数据
        /// </summary>
        public string JsonDatum
        {
            get;
            set;
        }

        /// <summary>
        /// 消息类型
        /// </summary>
        public EMsgType MsgType
        {
            set;
            get;
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetDatum<T>()
        {
            var obj = JsonHelper.DeserializeWithTypeName<T>(this.JsonDatum);

            return obj;
        }

        /// <summary>
        /// 设置数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        public void SetDatum<T>(T obj)
        {
            this.JsonDatum = JsonHelper.SerializeWithTypeName(obj);
        }
    }
}
